package com.yxw.springmvc.userBehavior.mq;

import com.alibaba.fastjson.JSONObject;
import com.yxw.springmvc.userBehavior.model.User;
import com.yxw.springmvc.userBehavior.util.CollectionUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 消息队列管理类
 * Author: yangxianwang
 * Date:   2016/9/23
 * Time:   8:53
 */
@Service
public class ServiceMQSendManage {

    private final static String INTERFACE = "interface.";

    @Resource
    private AmqpTemplate amqpTemplate;

    public void sendMsg(String routingKey, User user){
        try {
            if(!CollectionUtils.isEmpty(user)) {
                amqpTemplate.convertAndSend(INTERFACE + routingKey,  JSONObject.toJSONString(user));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
